package cn.edu.scau.cmi.chenxiaoqin.client;

import cn.edu.scau.cmi.chenxiaoqin.factory.BeefMeatFactory;
import cn.edu.scau.cmi.chenxiaoqin.factory.ChickenMeatFactory;
import cn.edu.scau.cmi.chenxiaoqin.factory.MeatFactory;
import cn.edu.scau.cmi.chenxiaoqin.factory.PorkMeatFactory;
import cn.edu.scau.cmi.chenxiaoqin.simpleFactoryMethod.Meat;
import javafx.application.Application;
import javafx.event.EventTarget;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

public class FactoryClient extends Application{
	public void start(Stage primaryStage) {
		//上下布局
		BorderPane pane =new BorderPane();
		//信息展示文本区域
		TextArea inforArea=new TextArea(" ");
		inforArea.setEditable(false);
		inforArea.setWrapText(true);
		pane.setTop(inforArea);
		//操作区域
		Label tip=new Label("请选择");
		ComboBox<String> comboBox = new ComboBox<String>();
		comboBox.setValue("肉的种类");
		comboBox.getItems().addAll( "牛肉","猪肉","鸡肉" );  
		Button okButton=new Button("确认");
		HBox hBox=new HBox(15);
		okButton.setOnAction(e->{
			Button okButton1= (Button) e.getSource();
			System.out.print(okButton1.getText());
			MeatFactory factory=null;
			String kindOfMeat=comboBox.getValue();
			if(!kindOfMeat.equals("肉的种类")) {
				if(kindOfMeat.equals("牛肉")) {
					factory=new BeefMeatFactory();
				}
				else if(kindOfMeat.equals("鸡肉")) {
					factory=new ChickenMeatFactory();
				}
				else {
					factory=new PorkMeatFactory();
				}
				Meat meat=factory.getMeat();
				inforArea.setText(meat.getBehavior());
			}
			else {
				inforArea.setText("请选择肉类！");
			}
		});
		
		
		hBox.setPadding(new Insets(15,15,15,15));
		hBox.getChildren().add(tip);
		hBox.getChildren().add(comboBox);
		hBox.getChildren().add(okButton);
		pane.setCenter(hBox);
		
		Scene scene =new Scene(pane,700,280);
		primaryStage.setTitle("工厂模式");
		primaryStage.setScene(scene);
		primaryStage.show();
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Application.launch(args);
	}
}
